<template>
  <div class="form-container">
    <el-form inline :model="form" ref="refForm" class="form-line" label-width="80">
      <el-form-item label="驿站名称" prop="name">
        <el-input size="default" v-model="form.name" placeholder="驿站名称/编号"></el-input>
      </el-form-item>
    </el-form>
    <div class="btn-container">
      <el-button type="primary" @click="handleReset(refForm as FormInstance)">重置</el-button>
      <el-button type="primary" @click="getList">查询</el-button>
    </div>
  </div>
  <div class="table-container">
    <el-table
      border
      :cell-style="{ textAlign: 'center', fontSize: '13px' }"
      :header-cell-style="{
        textAlign: 'center',
        fontWeight: '100',
        fontSize: '13px',
        color: 'white',
        backgroundColor: '#009688'
      }"
      :data="list"
      style="width: 100%"
    >
      <el-table-column prop="id" label="驿站编号" width="200" />
      <el-table-column prop="name" label="驿站名称" />
      <el-table-column prop="stationLevelName" label="驿站等级" />
      <el-table-column prop="acreage" label="面积" />
      <el-table-column prop="cityName" label="所属地市" />
      <el-table-column prop="countyName" label="所属区县" />
      <el-table-column prop="status" label="状态" />
      <el-table-column fixed="right" label="操作" width="250">
        <template #default="scope">
          <el-button link type="primary" size="small" @click="handleEdit(scope.row.id)"> 查看详情 </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination
        background
        size="small"
        v-model:current-page="form.pageNum"
        :page-sizes="[5, 10, 15, 20]"
        layout="prev, pager, next"
        :total="pageTotal"
        @change="getList"
        :page-size="form.pageSize"
      />
    </div>
  </div>
</template>

<script lang="tsx" name="CitySiteIndex" setup>
import { Site } from "@/api/interface/city/site";
import { getSiteListAPI } from "@/api/modules/city/siteAPI";
import { ElMessage, FormInstance } from "element-plus";
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
let pageTotal = ref<number>(0);
let form = ref<Site.Params>({
  province: JSON.parse(localStorage.getItem("userInfo") as string).province,
  city: JSON.parse(localStorage.getItem("userInfo") as string).city,
  name: "",
  pageNum: 1,
  pageSize: 10
});
const refForm = ref<FormInstance>();
const list = ref<Site.Row[]>([
  {
    id: 1,
    name: "string",
    code: "string",
    acreage: 0,
    city: "string",
    county: "string",
    stationType: "string",
    stationLevelName: "string"
  },
  {
    id: 1,
    name: "string",
    code: "string",
    acreage: 0,
    city: "string",
    county: "string",
    stationType: "string",
    stationLevelName: "string"
  },
  {
    id: 1,
    name: "string",
    code: "string",
    acreage: 0,
    city: "string",
    county: "string",
    stationType: "string",
    stationLevelName: "string"
  }
]);
const handleReset = (ruleForm: FormInstance) => {
  ruleForm.resetFields();
};
const handleEdit = (id: number) => {
  router.push({ path: "/cityLevel/citySite/detail", query: { id } });
};
const getList = async () => {
  const { rows, code, msg, total } = await getSiteListAPI(form.value);
  if (code == "200" && rows) {
    list.value = rows;
    if (total) {
      pageTotal.value = total;
    }
  } else {
    ElMessage.error(msg);
  }
};
onMounted(() => {
  getList();
});
</script>
<style lang="scss" scoped>
.form-container {
  padding: 10px;
  margin-bottom: 10px;
  background-color: white;
  .btn-container {
    display: inline-block;
    float: right;
    vertical-align: middle;
  }
  .el-form {
    display: inline-block;
  }
  .form-line {
    .el-form-item {
      margin: 0;
      margin-right: 20px;
    }
    .el-input {
      width: 240px;
    }
    .el-select {
      width: 240px;
    }
  }
}
.table-container {
  padding: 40px 10px;
  padding-bottom: 60px;
  background-color: white;
  .pagination-container {
    // display: inline-block;
    float: right;
    margin-top: 20px;
    background-color: white;
  }
}
::v-deep .el-form-item__label {
  font-size: 13px;
}
::v-deep .el-button > span {
  font-size: 13px;
}
::v-deep .el-input__inner {
  font-size: 13px;
}
</style>
